const child_process = require('child_process');
const { createLog } = require('./server/utils')

const hlog = createLog('HTTP')
const wlog = createLog('WSS')

function spawnChild(cmd, args = [], options = {}, callback = console.log) {
    const child = child_process.spawn(cmd, args, options);
    let stdout = '';
    let stderr = '';
    child.stdout.on('data', data => {
        stdout += data.toString();
        callback('stdout:', stdout)
    });
    child.stderr.on('data', data => {
        stderr += data.toString();
        callback('stderr:', stderr)
    });
    child.on('close', code => {
        callback('close', code);
    });
}

function main() {
    const httpChild = spawnChild('node', ['server/chatSocket.js'], {}, hlog)
    const wssChild = spawnChild('node', ['server/web.js'], {}, wlog)
}

main()

